#include<iostream>
#include<string>
#include<vector>
using namespace std;
const int N = 1e3 + 10;
int f[N][N];
string s1, s2;
int n, m;
int ans;
int main()
{
	cin >> s1 >> s2;
	n = s1.size();
	m = s2.size();
	s1 = " " + s1;
	s2 = " " + s2;
	int ma = 0;
	// aeeee
	// ee
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s1[i] == s2[j]) {
				f[i][j] = f[i - 1][j - 1] + 1;
				if (ma < f[i][j]) {
					ma = f[i][j];
					ans = i;
				}
			}
		}
	}
	//cout << ma << endl;
	//cout << ans << endl;
	if (ma == 0) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = ans - ma + 1; i <= ans; i++) {
		cout << s1[i];
	}
	return 0;
}